from seleniumbase import BaseCase
import pandas as pd
import math
from selenium.webdriver.common.by import By
BaseCase.main(__name__, __file__)
# 给定一组数据
data = [0.86, 0.89, 0.92, 0.95, 0.92, 0.94]
expected_value = 1  # 已知的期望值

class SelectTestClass(BaseCase):
    def test_base(self):
        # 计算每个数据点与期望值的差的平方
        squared_diffs = [(x - expected_value) ** 2 for x in data]

        # 计算差的平方的平均值
        variance = sum(squared_diffs) / len(data)

        # 计算标准差（平方根）
        std_dev = math.sqrt(variance)

        # 打印结果
        print("标准差为:", std_dev)
        # 打印结果

        self.open("https://www.500.com/")
        # 点击id为link6的元素
        self.js_click("a#link38")
        # 使用CSS选择器定位图片元素并点击它
        self.find_element("css selector", "img.close-icon").click()
        # 点击'析'
        self.js_click("a#link87")
        # 点击'百家欧赔'
        # 使用链接文本来点击链接
        self.click_link_text("百家欧赔")

#获取凯利值
        # 等待表格加载完成（使用CSS选择器）

        parent_element = self.find_element(By.ID, "5")

        # 获取parent_element内部的所有<table class="pl_table_data">元素
        tables = parent_element.find_elements(By.CSS_SELECTOR, 'table.pl_table_data')

        # 获取最后一个<table class="pl_table_data">元素
        last_table = tables[-1]  # 使用-1索引来获取列表中的最后一个元素

        table_data = []  # 初始化一个空数组来存储表格数据

        for tr_element in last_table.find_elements(By.TAG_NAME, 'tr'):
            row_data = []  # 初始化一个空数组来存储当前行的数据
            for td_element in tr_element.find_elements(By.TAG_NAME, 'td'):
                row_data.append(td_element.text)  # 将<td>的文本添加到当前行的数组中
            table_data.append(row_data)  # 将当前行的数组添加到表格数据的数组中

        # 现在table_data是一个二维数组，包含了表格的所有数据
        # 可以打印出来检查
        for row in table_data:
            print(row)

        self.sleep(1000)

        expected_option_texts = [
            "Set to 25%", "Set to 50%", "Set to 75%", "Set to 100%"
        ]
        option_texts = self.get_select_options("select#mySelect")
        self.assert_equal(option_texts, expected_option_texts)

        expected_option_indexes = ["0", "1", "2", "3"]
        option_indexes = self.get_select_options(
            "select#mySelect", attribute="index"
        )
        self.assert_equal(option_indexes, expected_option_indexes)

        expected_option_values = ["25%", "50%", "75%", "100%"]
        option_values = self.get_select_options(
            "select#mySelect", attribute="value"
        )
        self.assert_equal(option_values, expected_option_values)

        for index, option_text in enumerate(option_texts):
            self.select_option_by_text("#mySelect", option_text)
            selected_value = self.get_attribute("#mySelect", "value")
            self.assert_equal(selected_value, option_values[index])

        for index, option_value in enumerate(option_values):
            self.select_option_by_value("#mySelect", option_value)
            selected_value = self.get_attribute("#mySelect", "value")
            self.assert_equal(selected_value, option_values[index])

        for index, option_index in enumerate(option_indexes):
            self.select_option_by_index("#mySelect", option_index)
            # assert_attribute() combines get_attribute() and assert_equal()
            # It also highlights the element when Demo Mode is enabled.
            self.assert_attribute("#mySelect", "value", option_values[index])
        self.sleep(1000)